#  Copyright (c) 2021- ~, XIWANG
#  
#  OLSR simulation throughput analyze .tr
#  Used in awk
#  Clone from https://gitee.com/WangXi_Chn/olsr_-analysis.git
#  Note in https://www.yuque.com/wangxi_chn
#  
#  Change Logs:
#  Date             Author      Notes			Mail
#  2021-3-15        XiWang      first version	WangXi_Chn@foxmail.com

BEGIN {
    init = 0;
    i = 0;
}

{
    event = $1;
    time = $2;
    node_nb=substr($3,2,1);
    trace_type = $4;
    flag = $5;
    packet_id = $6
    pkt_type = $7;
    pkt_size = $8;

    if (event== "r" && trace_type == "AGT" && pkt_type== "cbr"){
        pkt_byte_sum[i+1] = pkt_byte_sum[i] + pkt_size;
        if(init == 0){
            start_time = time;
            init = 1;
        }
        end_time[i] = time;
        i = i + 1;
    }
}

END {
    # the first transation record setted zero means transport begin
    printf("%.2f\t%.2f\n",end_time[0],0);
    for(j=1;j<i;j++){
        th = pkt_byte_sum[j] / (end_time[j] - start_time)*8/1000;
        printf("%.2f\t%.2f\n",end_time[j],th);
    }
    # the fanal transation record setted zero means transport end
    printf("%.2f\t%.2f\n",end_time[i-1],0);
}

#/************************ (C) COPYRIGHT 2021 XIWANG**************END OF FILE****/
